package com.imis.module.system.bus;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imis.base.constant.CommonConstant;
import com.imis.base.constant.enums.SysTipEnum;
import com.imis.base.globle.Result;
import com.imis.base.util.ConvertUtils;
import com.imis.base.util.CurrentUserUtils;
import com.imis.module.base.BaseBus;
import com.imis.module.system.model.converter.SysDictConverter;
import com.imis.module.system.model.po.SysDict;
import com.imis.module.system.model.po.SysDictItem;
import com.imis.module.system.model.ro.*;
import com.imis.module.system.model.vo.SysDictItemVO;
import com.imis.module.system.model.vo.SysDictVO;
import com.imis.module.system.service.ISysDictItemService;
import com.imis.module.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 字典项 业务处理类
 * </p>
 *
 * @author XinLau
 * @since 2020-03-23
 */
@Service
public class SysDictBus extends BaseBus {

    /**
     * 字典项 服务类
     */
    private ISysDictService serviceBySysDictService;

    @Autowired
    public void setServiceBySysDictService(ISysDictService serviceBySysDictService) {
        this.serviceBySysDictService = serviceBySysDictService;
    }

    /**
     * 字典值 服务类
     */
    private ISysDictItemService serviceBySysDictItemService;

    @Autowired
    public void setServiceBySysDictItemService(ISysDictItemService serviceBySysDictItemService) {
        this.serviceBySysDictItemService = serviceBySysDictItemService;
    }

    /**
     * 添加字典项校验
     *
     * @param sysDictAddRO - 字典项添加对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/3/9 9:47
     */
    private Result dictAddVerification(SysDictAddRO sysDictAddRO) {
        SysDict sysDict = serviceBySysDictService.queryDictByName(sysDictAddRO.getDictName());
        if (sysDict != null) {
            if (sysDict.getDelFlag().equals(CommonConstant.DEL_FLAG_DELETE)) {
//                根据字典项信息查询，该字典项被逻辑删除 删除状态（1已删除 0未删除）
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ADD_ERR_NAME_DELETE.toString(), sysDict.getDictName());
                return Result.errorsFormat(SysTipEnum.DICT_ADD_ERR_NAME_DELETE, sysDict.getDictName());
            }
//            根据字典项信息查询，该字典项存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ADD_ERR_NAME_REPEAT.toString(), sysDict.getDictName());
            return Result.errorsFormat(SysTipEnum.DICT_ADD_ERR_NAME_REPEAT, sysDict.getDictName());
        }
        sysDict = serviceBySysDictService.queryDictByCode(sysDictAddRO.getDictCode());
        if (sysDict != null) {
            if (sysDict.getDelFlag().equals(CommonConstant.DEL_FLAG_DELETE)) {
//                根据字典项编码查询，该字典项编码被逻辑删除 删除状态（1已删除 0未删除）
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ADD_ERR_CODE_DELETE.toString(), sysDict.getDictCode());
                return Result.errorsFormat(SysTipEnum.DICT_ADD_ERR_CODE_DELETE, sysDict.getDictCode());
            }
//            根据字典项编码查询，该字典项编码存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ADD_ERR_CODE_REPEAT.toString(), sysDict.getDictCode());
            return Result.errorsFormat(SysTipEnum.DICT_ADD_ERR_CODE_REPEAT, sysDict.getDictCode());
        }
        return Result.ok();
    }

    /**
     * 删除字典项校验
     *
     * @param sysDict - 字典项
     * @return Result
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/3/9 9:47
     */
    private Result dictDeleteVerification(SysDict sysDict) {
        Result<SysDictVO> result = new Result<>();
        if (ConvertUtils.isEmpty(sysDict)) {
//            1.根据字典项信息查询，该字典项不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_DELETE_ERR_NON.toString());
            return result.errorFormat(SysTipEnum.DICT_DELETE_ERR_NON);
        }
//        判断字典项是否使用
        List<SysDictItem> sysDictItemList = serviceBySysDictItemService.selectSysDictItemListByDictId(sysDict.getId());
        if (sysDictItemList.size() > 0) {
//            2.根据字典项信息查询，该字典项已使用
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_DELETE_ERR_USE.toString(), sysDict.getDictName());
            return result.errorFormat(SysTipEnum.DICT_DELETE_ERR_USE, sysDict.getDictName());
        }
        result.setResult(SysDictConverter.INSTANCE.domain2Vo(sysDict));
        return result;
    }

    /**
     * 更新字典项校验
     *
     * @param sysDictUpdateRO - 字典项修改对象
     * @return Result
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/3/9 9:47
     */
    private Result dictUpdateVerification(SysDictUpdateRO sysDictUpdateRO) {
        SysDict sysDict = serviceBySysDictService.getById(sysDictUpdateRO.getId());
        Result<SysDictVO> result = new Result<>();
        if (ConvertUtils.isEmpty(sysDict)) {
//            1.根据字典项信息查询，该字典项不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_UPDATE, SysTipEnum.DICT_UPDATE_ERR_NON.toString(), sysDictUpdateRO.getDictName());
            return result.errorFormat(SysTipEnum.DICT_UPDATE_ERR_NON, sysDictUpdateRO.getDictName());
        }
//        2.校验字典项名重复
        if (!sysDict.getDictName().equals(sysDictUpdateRO.getDictName())) {
//            前端传递字典项名与数据库查询出来的不一致做字典项名重复校验（字典项名修改做校验）
            SysDict sysDictByDictName = serviceBySysDictService.queryDictByName(sysDictUpdateRO.getDictName());
            if (sysDictByDictName != null) {
//                根据字典项名查询，该字典项名存在
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_UPDATE_ERR_NAME_REPEAT.toString(), sysDictUpdateRO.getDictName());
                return result.errorFormat(SysTipEnum.DICT_UPDATE_ERR_NAME_REPEAT, sysDictUpdateRO.getDictName());
            }
        }
//        3.字典项编码重复校验
        if (!sysDict.getDictCode().equals(sysDictUpdateRO.getDictCode())) {
            SysDict sysDictByDictCode = serviceBySysDictService.queryDictByCode(sysDictUpdateRO.getDictCode());
            if (sysDictByDictCode != null) {
//                根据字典项编码查询，该字典项编码存在
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_UPDATE_ERR_CODE_REPEAT.toString(), sysDictUpdateRO.getDictCode());
                return result.errorFormat(SysTipEnum.DICT_UPDATE_ERR_CODE_REPEAT, sysDictUpdateRO.getDictCode());
            }
        }
        result.setResult(SysDictConverter.INSTANCE.domain2Vo(sysDict));
        return result;
    }

    /**
     * 添加字典值校验
     *
     * @param sysDictItemAddRO - 字典值添加对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/3/9 9:47
     */
    private Result dictItemAddVerification(SysDictItemAddRO sysDictItemAddRO) {
        SysDictItem sysDictItem = serviceBySysDictItemService.selectDictItemByTextAndDict(sysDictItemAddRO.getItemText(), sysDictItemAddRO.getDictId());
        if (sysDictItem != null) {
            if (sysDictItem.getStatus().equals(CommonConstant.STATUS_ERR)) {
//                根据字典值信息查询，该字典值被停用 状态（1启用 0不启用）
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_ADD_ERR_TEXT_DISABLED.toString(), sysDictItem.getItemText());
                return Result.errorsFormat(SysTipEnum.DICT_ITEM_ADD_ERR_TEXT_DISABLED, sysDictItem.getItemText());
            }
//            根据字典项信息查询，该字典项存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_ADD_ERR_TEXT_REPEAT.toString(), sysDictItem.getItemText());
            return Result.errorsFormat(SysTipEnum.DICT_ITEM_ADD_ERR_TEXT_REPEAT, sysDictItem.getItemText());
        }
        sysDictItem = serviceBySysDictItemService.selectDictItemByValueAndDict(sysDictItemAddRO.getItemValue(), sysDictItemAddRO.getDictId());
        if (sysDictItem != null) {
            if (sysDictItem.getStatus().equals(CommonConstant.STATUS_ERR)) {
//                根据字典项编码查询，该字典项编码被被停用 状态（1启用 0不启用）
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_ADD_ERR_VALUE_DISABLED.toString(), sysDictItem.getItemValue());
                return Result.errorsFormat(SysTipEnum.DICT_ITEM_ADD_ERR_VALUE_DISABLED, sysDictItem.getItemValue());
            }
//            根据字典项编码查询，该字典项编码存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_ADD_ERR_VALUE_REPEAT.toString(), sysDictItem.getItemValue());
            return Result.errorsFormat(SysTipEnum.DICT_ITEM_ADD_ERR_VALUE_REPEAT, sysDictItem.getItemValue());
        }
        return Result.ok();
    }

    /**
     * 删除字典值校验
     *
     * @param sysDictItem - 字典值
     * @return Result
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/3/9 9:47
     */
    private Result dictItemDeleteVerification(SysDictItem sysDictItem) {
        Result<SysDictItemVO> result = new Result<>();
        if (ConvertUtils.isEmpty(sysDictItem)) {
//            1.根据字典值信息查询，该字典值不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_ITEM_DELETE_ERR_NON.toString());
            return result.errorFormat(SysTipEnum.DICT_ITEM_DELETE_ERR_NON);
        }
//        2.判断字典值是否使用 TODO:This 判断字典值是否使用
        result.setResult(SysDictConverter.INSTANCE.domain2vo(sysDictItem));
        return result;
    }

    /**
     * 更新字典值校验
     *
     * @param sysDictItemUpdateRO - 字典值修改对象
     * @return Result
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/3/9 9:47
     */
    private Result dictItemUpdateVerification(SysDictItemUpdateRO sysDictItemUpdateRO) {
        SysDictItem sysDictItem = serviceBySysDictItemService.getById(sysDictItemUpdateRO.getId());
        Result<SysDictItemVO> result = new Result<>();
        if (ConvertUtils.isEmpty(sysDictItem)) {
//            1.根据字典值信息查询，该字典值不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_UPDATE, SysTipEnum.DICT_ITEM_UPDATE_ERR_NON.toString(), sysDictItemUpdateRO.getItemText());
            return result.errorFormat(SysTipEnum.DICT_ITEM_UPDATE_ERR_NON, sysDictItemUpdateRO.getItemText());
        }
//        2.校验字典值文本重复
        if (!sysDictItem.getItemText().equals(sysDictItemUpdateRO.getItemText())) {
//            前端传递字典值文本与数据库查询出来的不一致做字典值文本重复校验（字典值修改做校验）
            SysDictItem sysDictByTextAndDict = serviceBySysDictItemService.selectDictItemByTextAndDict(sysDictItemUpdateRO.getItemText(), sysDictItem.getDictId());
            if (sysDictByTextAndDict != null) {
//                根据字典值文本和字典项查询，该字典值文本存在
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_UPDATE_ERR_TEXT_REPEAT.toString(), sysDictItemUpdateRO.getItemText());
                return result.errorFormat(SysTipEnum.DICT_ITEM_UPDATE_ERR_TEXT_REPEAT, sysDictItemUpdateRO.getItemText());
            }
        }
//        3.字典字典值值重复校验
        if (!sysDictItem.getItemValue().equals(sysDictItemUpdateRO.getItemValue())) {
            SysDict sysDictByDictCode = serviceBySysDictService.queryDictByCode(sysDictItemUpdateRO.getItemValue());
            if (sysDictByDictCode != null) {
//                根据字典项字典值值字典项查询，该字典值值存在
                addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_UPDATE_ERR_VALUE_REPEAT.toString(), sysDictItemUpdateRO.getItemValue());
                return result.errorFormat(SysTipEnum.DICT_ITEM_UPDATE_ERR_VALUE_REPEAT, sysDictItemUpdateRO.getItemValue());
            }
        }
        result.setResult(SysDictConverter.INSTANCE.domain2vo(sysDictItem));
        return result;
    }

    /**
     * 分页查询字典项
     *
     * @param pagingQueryDictDTO - 字典项查询对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result pagingQuerySysDictListByParameter(final PagingQueryDictDTO pagingQueryDictDTO) {
        try {
            Page<SysDictVO> sysDictListByParameter = serviceBySysDictService.pagingQuerySysDictListByParameter(pagingQueryDictDTO);
            return Result.ok(sysDictListByParameter);
        } catch (Exception e) {
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_QUERY, SysTipEnum.DICT_PAGE_QUERY_ERR.toString(), e.getMessage());
            return Result.errorsFormat(SysTipEnum.DICT_PAGE_QUERY_ERR, e.getMessage());
        }
    }

    /**
     * 字典项添加接口
     *
     * @param sysDictAddRO - 字典项添加对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result addDict(SysDictAddRO sysDictAddRO) {
//        1.校验字典项重复
        Result result = dictAddVerification(sysDictAddRO);
        if (!result.isSuccess()) {
            return result;
        }
//        2.创建新字典项
        SysDict sysDict = SysDictConverter.INSTANCE.addRo2domain(sysDictAddRO);
        sysDict.setCreateBy(CurrentUserUtils.getLoginUserId());
        if (serviceBySysDictService.saveDict(sysDict)) {
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ADD_OK.toString(), sysDict.getDictName());
            return result.success();
        }
//        添加失败
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ADD_ERR.toString(), sysDictAddRO.getDictName());
        return result.errorFormat(SysTipEnum.DICT_ADD_ERR, sysDictAddRO.getDictName());
    }

    /**
     * 字典项删除接口
     *
     * @param dictIdentification - 字典项标识
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result deleteDict(final Long dictIdentification) {
//        1.删除字典项校验
        SysDict sysDict = serviceBySysDictService.getById(dictIdentification);
        Result<SysDictVO> result = dictDeleteVerification(sysDict);
        if (!result.isSuccess()) {
            return result;
        }
//        2.删除字典项
        boolean deleteDict = serviceBySysDictService.deleteDict(dictIdentification);
        if (!deleteDict) {
//            删除字典项失败
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_DELETE_ERR.toString(), sysDict.getDictName());
            return result.errorFormat(SysTipEnum.DICT_DELETE_ERR, sysDict.getDictName());
        }
//        TODO:this 删除对应字典项的缓存
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_DELETE_OK.toString(), sysDict.getDictName());
        return Result.ok();
    }

    /**
     * 字典项查看接口
     *
     * @param dictIdentification - 字典项标识
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result queryDictById(final Long dictIdentification) {
        SysDict sysDict = serviceBySysDictService.getById(dictIdentification);
        if (ConvertUtils.isEmpty(sysDict)) {
//            1.根据字典项信息查询，该字典项不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_QUERY_ERR.toString());
            return Result.errorsFormat(SysTipEnum.DICT_QUERY_ERR);
        }
        return Result.ok(SysDictConverter.INSTANCE.domain2Vo(sysDict));
    }

    /**
     * 字典项更新接口
     *
     * @param sysDictUpdateRO - 字典项更新对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result updateDict(SysDictUpdateRO sysDictUpdateRO) {
//        1.修改字典项校验
        Result<SysDictVO> result = dictUpdateVerification(sysDictUpdateRO);
        if (!result.isSuccess()) {
            return result;
        }
//        2.字典项信息修改
        boolean update = serviceBySysDictService.updateByDictIdentification(sysDictUpdateRO);
        if (update) {
            return Result.ok();
        }
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_UPDATE_ERR.toString(), sysDictUpdateRO.getDictName());
        return result.errorFormat(SysTipEnum.DICT_UPDATE_ERR, sysDictUpdateRO.getDictName());
    }

    /**
     * 分页查询字典值
     *
     * @param pagingQueryDictItemDTO - 字典值查询对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result pagingQuerySysDictItemListByParameter(final PagingQueryDictItemDTO pagingQueryDictItemDTO) {
        try {
            Page<SysDictItemVO> sysDictItemListByParameter = serviceBySysDictItemService.pagingQuerySysDictItemListByParameter(pagingQueryDictItemDTO);
            return Result.ok(sysDictItemListByParameter);
        } catch (Exception e) {
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_QUERY, SysTipEnum.DICT_ITEM_PAGE_QUERY_ERR.toString(), e.getMessage());
            return Result.errorsFormat(SysTipEnum.DICT_ITEM_PAGE_QUERY_ERR, e.getMessage());
        }
    }

    /**
     * 根据字典项获取字典值
     *
     * @param dictIdentification - 字典项标识
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result queryDictItemByDict(final Long dictIdentification) {
//        字典项校验
        SysDict sysDict = serviceBySysDictService.getById(dictIdentification);
        if (ConvertUtils.isEmpty(sysDict)) {
//            1.根据字典项标识查询，该字典项不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_QUERY_ERR_DICT_NON.toString());
            return Result.errorsFormat(SysTipEnum.DICT_QUERY_ERR_DICT_NON);
        }
//        2.查询字典值
        List<SysDictItem> sysDictItemList = serviceBySysDictItemService.selectSysDictItemListByDictId(sysDict.getId());
        if (sysDictItemList.size() > 0) {
            return Result.ok(SysDictConverter.INSTANCE.domains2vos(sysDictItemList));
        }
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_QUERY_ERR.toString());
        return Result.errorsFormat(SysTipEnum.DICT_QUERY_ERR);
    }

    /**
     * 字典值添加接口
     *
     * @param sysDictItemAddRO - 字典值添加对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result addDictItem(SysDictItemAddRO sysDictItemAddRO) {
//        1.校验字典项重复
        Result<SysDictItemVO> result = dictItemAddVerification(sysDictItemAddRO);
        if (!result.isSuccess()) {
            return result;
        }
//        2.创建新字典项
        SysDictItem sysDictItem = SysDictConverter.INSTANCE.addRo2domain(sysDictItemAddRO);
        sysDictItem.setCreateBy(CurrentUserUtils.getLoginUserId());
        if (serviceBySysDictItemService.saveDictItem(sysDictItem)) {
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_ADD_OK.toString(), sysDictItem.getItemText());
            return result.success();
        }
//        添加失败
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_ADD_ERR.toString(), sysDictItem.getItemText());
        return result.errorFormat(SysTipEnum.DICT_ITEM_ADD_ERR, sysDictItem.getItemText());
    }

    /**
     * 字典值删除接口
     *
     * @param dictItemIdentification - 字典值标识
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result deleteDictItem(final Long dictItemIdentification) {
//        删除字典值校验
        SysDictItem sysDictItem = serviceBySysDictItemService.getById(dictItemIdentification);
        Result<SysDictItemVO> result = dictItemDeleteVerification(sysDictItem);
        if (!result.isSuccess()) {
            return result;
        }
//        2.删除字典值
        boolean deleteDictItem = serviceBySysDictItemService.deleteDictItem(dictItemIdentification);
        if (!deleteDictItem) {
//            删除字典值失败
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_ITEM_DELETE_ERR.toString(), sysDictItem.getItemText());
            return result.errorFormat(SysTipEnum.DICT_ITEM_DELETE_ERR, sysDictItem.getItemText());
        }
//        TODO:this 删除对应字典值的缓存
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_ITEM_DELETE_OK.toString(), sysDictItem.getItemText());
        return Result.ok();
    }

    /**
     * 字典值查看接口
     *
     * @param dictItemIdentification - 字典值标识
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result queryDictItemById(final Long dictItemIdentification) {
        SysDictItem sysDictItem = serviceBySysDictItemService.getById(dictItemIdentification);
        if (ConvertUtils.isEmpty(sysDictItem)) {
//            1.根据字典值信息查询，该字典值不存在
            addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_DELETE, SysTipEnum.DICT_ITEM_QUERY_ERR.toString());
            return Result.errorsFormat(SysTipEnum.DICT_ITEM_QUERY_ERR);
        }
        return Result.ok(SysDictConverter.INSTANCE.domain2vo(sysDictItem));
    }

    /**
     * 字典值修改接口
     *
     * @param sysDictItemUpdateRO - 字典值更新对象
     * @return Result -
     * @author XinLau
     * @creed The only constant is change ! ! !
     * @since 2020/5/12 14:54
     */
    public Result updateDictItem(SysDictItemUpdateRO sysDictItemUpdateRO) {
//        修改字典值校验
        Result<SysDictItemVO> result = dictItemUpdateVerification(sysDictItemUpdateRO);
        if (!result.isSuccess()) {
            return result;
        }
//        2.字典值信息修改
        boolean update = serviceBySysDictItemService.updateByDictItemIdentification(sysDictItemUpdateRO);
        if (update) {
            return Result.ok();
        }
        addLog(CommonConstant.LOG_TYPE_OPERATE, CommonConstant.OPERATE_TYPE_ADD, SysTipEnum.DICT_ITEM_UPDATE_ERR.toString(), sysDictItemUpdateRO.getItemText());
        return result.errorFormat(SysTipEnum.DICT_ITEM_UPDATE_ERR, sysDictItemUpdateRO.getItemText());
    }

}